//
//  ViewController.m
//  ReactiveObjCDemo
//
//  Created by xth on 2017/12/6.
//  Copyright © 2017年 xth. All rights reserved.
//

#import "ViewController.h"
#import "CellModel.h"
#import "RACSignerVC.h"
#import "RACSubjectVC.h"
#import "RACCommandVC.h"
#import "LoginViewController.h"
#import "RACSequenceVC.h"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSArray *items;

@end

@implementation ViewController

- (NSArray *)items {
    if (!_items) {
        
        CellModel *m1 = [[CellModel alloc] init];
        m1.title = @"RACSigner基础知识点";
        m1.class = [RACSignerVC class];
        
        CellModel *m2 = [[CellModel alloc] init];
        m2.title = @"RACSubject基础知识点";
        m2.class = [RACSubjectVC class];

        CellModel *m3 = [[CellModel alloc] init];
        m3.title = @"RACCommand基础知识点";
        m3.class = [RACCommandVC class];
        
        CellModel *m4 = [[CellModel alloc] init];
        m4.title = @"RACCommand基础知识点";
        m4.class = [RACSequenceVC class];
        
//        CellModel *m4 = [[CellModel alloc] init];
//        m4.title = @"MVVM登录操作";
//        m4.class = [LoginViewController class];
        
        _items = @[m1, m2, m3, m4];
        
    }
    return _items;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"ReactiveObjCDemo";
    
    [self.view addSubview:self.tableView];
    
    [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"doubi"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"doubi"];
    }
    
    CellModel *model = self.items[indexPath.row];
    
    cell.textLabel.text = model.title;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    CellModel *model = self.items[indexPath.row];
    
    UIViewController *targetVC = [[model.class alloc] init];
    targetVC.title = model.title;
    
    [self.navigationController pushViewController:targetVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

